package cn.edu.nju.software.service.impl;

import java.sql.SQLException;

import javax.swing.tree.DefaultMutableTreeNode;

import cn.edu.nju.software.bean.storage.Category;
import cn.edu.nju.software.dao.intf.CategoryDao;
import cn.edu.nju.software.service.intf.CategoryService;
import cn.edu.nju.software.util.Constants;

public class CategoryServiceImpl implements CategoryService {

	private CategoryDao categoryDao;

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	@Override
	public DefaultMutableTreeNode getAllCategories() throws SQLException {
		Category rootCategory = new Category(Constants.ROOT_CATEOGRY_ID, "", -1);
		return categoryDao.getAllSubCategories(rootCategory);
	}

	@Override
	public DefaultMutableTreeNode getSubCategories(Category category) throws SQLException {
		return categoryDao.getAllSubCategories(category);
	}

	@Override
	public int addCategory(Category category) throws SQLException {
		return categoryDao.addCategory(category);
	}

	@Override
	public boolean deleteCategory(int categoryID) throws SQLException {
		return categoryDao.removeCategory(categoryID);
	}

	@Override
	public boolean modifyCategoryInfo(Category category) throws SQLException {
		return categoryDao.updateCategoryName(category);
	}

}
